﻿using System;
using System.Collections.Generic;
using System.Text;

namespace Sinacor.Servico.Bovespa.Corretagem.Service.ServiceImplementation.Translator.BusinessEntityToDataContract
{
    public class Taxa
    {
        #region [PUB] ToTaxaResponse
        public DataContract.Response.TaxaResponse ToTaxaResponse(BusinessEntity.Taxa from)
        {
            DataContract.Response.TaxaResponse taxa;
            if (from == null)
                return null;
            else
            {
                taxa = new DataContract.Response.TaxaResponse();

                taxa.Cliente = (DataContract.Enum.TipoCliente)from.Cliente;
                taxa.CodigoBolsa = from.CodigoBolsa;
                taxa.Liquidacao = (DataContract.Enum.TipoLiquidacao)from.Liquidacao;

                taxa.Mercado = from.Mercado;
                taxa.MercadoOrigem = from.MercadoOrigem;
                taxa.NaturezaOperacao = (DataContract.Enum.TipoNaturezaOperacao)from.NaturezaOperacao;

                taxa.NomeBolsa = from.NomeBolsa;
                taxa.NomeMercado = from.NomeMercado;
                taxa.NomeMercadoOrigem = from.NomeMercadoOrigem;

                taxa.Operacao = (DataContract.Enum.TipoOperacao)from.Operacao;
                taxa.Papel = (DataContract.Enum.TipoPapel)from.Papel;

                taxa.PercEmoluentoBovespa = from.PercEmoluentoBovespa;
                taxa.PercEmoluentoCBLC = from.PercEmoluentoCBLC;
                taxa.PercRegistroBovespa = from.PercRegistroBovespa;

                taxa.PercRegistroCBLC = from.PercRegistroCBLC; 

                if (from.Periodo != null)
                {
                    taxa.Periodo = new DataContract.Response.PeriodoResponse{
                                        DataInicial = from.Periodo.DataInicial,
                                        DataFinal = from.Periodo.DataFinal
                                    };
                }
                
            }
            return taxa;
        }
        #endregion

        #region [PUB] ToTaxaResponse
        public List<DataContract.Response.TaxaResponse> ToTaxaResponse(List<BusinessEntity.Taxa> from)
        {
            List<DataContract.Response.TaxaResponse> retorno = new List<DataContract.Response.TaxaResponse>();
            if (from == null)
                return null;
            else
            {
                DataContract.Response.TaxaResponse taxa;
                foreach (BusinessEntity.Taxa item in from)
                {
                    taxa = new DataContract.Response.TaxaResponse();

                    taxa.Cliente = (DataContract.Enum.TipoCliente)item.Cliente;
                    taxa.CodigoBolsa = item.CodigoBolsa;
                    taxa.Liquidacao = (DataContract.Enum.TipoLiquidacao)item.Liquidacao;

                    taxa.Mercado = item.Mercado;
                    taxa.MercadoOrigem = item.MercadoOrigem;
                    taxa.NaturezaOperacao = (DataContract.Enum.TipoNaturezaOperacao)item.NaturezaOperacao;

                    taxa.NomeBolsa = item.NomeBolsa;
                    taxa.NomeMercado = item.NomeMercado;
                    taxa.NomeMercadoOrigem = item.NomeMercadoOrigem;

                    taxa.Operacao = (DataContract.Enum.TipoOperacao)item.Operacao;
                    taxa.Papel = (DataContract.Enum.TipoPapel)item.Papel;

                    taxa.PercEmoluentoBovespa = item.PercEmoluentoBovespa;
                    taxa.PercEmoluentoCBLC = item.PercEmoluentoCBLC;
                    taxa.PercRegistroBovespa = item.PercRegistroBovespa;

                    taxa.PercRegistroCBLC = item.PercRegistroCBLC;

                    if (item.Periodo != null)
                    {
                        taxa.Periodo = new DataContract.Response.PeriodoResponse {
                                            DataInicial = item.Periodo.DataInicial,
                                            DataFinal = item.Periodo.DataFinal
                                        };                        
                    }

                    retorno.Add(taxa);
                }

            }
            return retorno;
        }
        #endregion

    }
}
